/*
 * @Author: Warren
 * @Date: 2024-12-27 09:12:05
 * @LastEditors: Warren
 * @LastEditTime: 2025-07-23 22:24:39
 * @FilePath: /nest-web/src/main.ts
 * @Description: 入口文件
 */

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ResponseInterceptor } from './interceptors/response/response.interceptor';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';


/* 配置端口号 */
const PORT = process.env.PORT ?? 3006;
/* 全局 api 统一前缀 */
const GLOBAL_PREFIX = 'nest/'

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    // 设置全局前缀
    app.setGlobalPrefix(GLOBAL_PREFIX); 

    /* 全局注册 统一返回 拦截器 */
    app.useGlobalInterceptors(new ResponseInterceptor())

    /* 配置 swagger */
    const docConfig = new DocumentBuilder()
        .setTitle('Cats example')
        .setDescription('The cats API description')
        .setVersion('1.0')
        .addTag('cats')
        .build();
    const documentFactory = () => SwaggerModule.createDocument(app, docConfig);
    SwaggerModule.setup('docs', app, documentFactory);


    await app.listen(PORT, () => {
        console.log('==========================');
        console.log(`访问 API: ${PORT}/${GLOBAL_PREFIX}`);
        console.log('==========================');
    })
}
bootstrap();
